layui.define([ 'form', 'laydate', 'table','auditApi'], function(exports) {
	var form = layui.form;
	var auditApi = layui.auditApi;
	var index = layui.index;
	var table = layui.table;
	var attractionId = null;
	var attractionsTable = null;
	var view = {
			init:function(id){
				attractionId = id;
				this.initTable();
				Lib.initGenrealForm($("#updateForm"),form);
				this.initSubmit();
			},
			initTable:function(){
				attractionsTable = table.render({
					elem : '#attractionsTable',
					height : 'full-380',
					method : 'get',
					url : Common.ctxPath + '/web/travel_attractions_line/queryTravelAttractionsLineInfo.json?attractionId='+attractionId //数据接口
					,page : {"layout":['count','prev', 'page', 'next']} //开启分页
					,limit : 10,
					cols : [ [ //表头
						// {
						// 	type : 'checkbox',
						// 	fixed:'left',
						// },
						{
							field : 'attsId',
							title : '景点编号',
							width : 100,
							fixed:'left',
							sort : true
						}, {
							field : 'attsName',
							title : '标题',
							width : 220
						}, {
							field : 'content',
							title : '描述',
							width : 220
						}, {
							field : 'type',
							title : '材料类型',
							width : 120,
							templet: '#typeTemplet'
						}, {
							field : 'address',
							title : '材料',
							width : 120,
							templet: '#urlTemplet'
						}

					] ]

				});

				//监听点击方法
				$(document).on('click', '.preview-all', function (data) {
					// var obj = data.target.dataset;
					var clickObject = data.target; //点击的对象
					var url = clickObject.src; //图片、视频 地址
					var type = $(clickObject).data('type'); //点击的类型：1-图片，2-音频；3-视频
					if (type == 1) {
						previewPicture(url);
					}else if (type == 2) {
						previewVideo(url);
					}else if (type == 3) {
						previewVideo(url);
					}
				});
				//图片预览，传url
				function previewPicture(url) {
					layer.photos({
						photos: {
							"title": '预览图',
							"id": 222,
							"start": 0,
							"data": [{
								"src": url
							}]
						}
						// ,closeBtn: 1 //是否显示关闭按钮
					});
				}
//视频预览，传url,width,height
				function previewVideo(url, width, height) {
					width = width ? width : '65%';
					height = height ? height : '65%';
					var content = '<video width="100%" height="90%"  controls="controls" autobuffer="autobuffer"  autoplay="autoplay" loop="loop">' +
						'<source src="' + url + '" type="video/mp4"></source></video>';
					layer.open({
						type: 1,
						maxmin: true, //打开放大缩小按钮
						title: '视频播放',
						area: [width, height],
						content: content,
					});
				}
				//文件预览
				function previewFile(url) {
					window.location.href = url;
				}
			},
			initSubmit:function(){
				$("#auditTravelAttractionsLine").click(function(){
					auditApi.audit($("#updateForm"),function(){
						parent.window.dataReload();
						Common.info("审核成功");
						Lib.closeFrame();
					});
				});
				
				$("#auditTravelAttractionsLine-cancel").click(function(){
					Lib.closeFrame();
				});
			}
	}
	 exports('audit',view);
});